context('blma comCrime')
library(parallel)
library(tictoc)
cores <- detectCores()
#cores <- 1
test_that('comCrime produces correct results BIC', {
	set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results BIC')
    result <- sampler(100000, vy, mX, prior='BIC', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, 
c(
0.94740000000000002,0.26622000000000001,0.08648000000000000,
0.43586999999999998,0.09908000000000000,0.45071000000000000,
0.04505000000000000,0.07826000000000000,0.04751000000000000,
0.20030000000000001,0.09268000000000000,0.03688000000000000,
0.11712000000000000,0.14110000000000000,0.02372000000000000,
0.03100000000000000,0.08356000000000000,0.04962000000000000,
0.04672000000000000,0.05529000000000000,0.06586000000000000,
0.07400000000000000,0.06235000000000000,0.04791000000000000,
0.03643000000000000,0.02986000000000000,0.07804999999999999,
0.04897000000000000,0.07392000000000000,0.03489000000000000,
0.07693000000000000,0.03548000000000000,0.04866000000000000,
0.02920000000000000,0.04345000000000000,0.02995000000000000,
0.03347000000000000,0.04446000000000000,0.03263000000000000,
0.80427000000000004,0.18221000000000001,0.05037000000000000,
0.21812000000000001,0.77812999999999999,0.04353000000000000,
0.12110000000000000,0.02568000000000000,0.02440000000000000,
0.92418000000000000,0.98036000000000001,0.97057000000000004,
0.04015000000000000,0.05150000000000000,0.15984000000000001,
0.68164999999999998,0.03199000000000000,0.03791000000000000,
0.03491000000000000,0.03524000000000000,0.37684000000000001,
0.05378000000000000,0.08116000000000000,0.05427000000000000,
0.06267000000000000,0.04224000000000000,0.09243000000000000,
0.07270000000000000,0.05966000000000000,0.03249000000000000,
0.02321000000000000,0.90103999999999995,0.06898000000000000,
0.04904000000000000,0.02438000000000000,0.09001000000000001,
0.03362000000000000,0.02942000000000000,0.13260000000000000,
0.37035000000000001,0.23374000000000000,0.24353000000000000,
0.02644000000000000,0.02986000000000000,0.03506000000000000,
0.03605000000000000,0.02414000000000000,0.24012000000000000,
0.02817000000000000,0.21396999999999999,0.38860000000000000,
0.04076000000000000,0.02999000000000000,0.33513999999999999,
0.04466000000000000,0.03532000000000000,0.02461000000000000,
0.02493000000000000,0.02511000000000000,0.70140000000000002
  )
, tolerance = 1e-5)
})
test_that('comCrime produces correct results ZE', {
	set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results ZE')
    result <- sampler(100000, vy, mX, prior='ZE', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, 
				 c(
0.94652000000000003,0.76881999999999995,0.21004000000000000,
0.80601999999999996,0.18861000000000000,0.61153999999999997,
0.15892999999999999,0.31552999999999998,0.18381000000000000,
0.46372000000000002,0.28755999999999998,0.24101000000000000,
0.16950999999999999,0.22846000000000000,0.09386000000000000,
0.11037000000000000,0.19811000000000001,0.16356999999999999,
0.23360000000000000,0.13303999999999999,0.21229999999999999,
0.19106000000000001,0.23682000000000000,0.17039000000000001,
0.15121999999999999,0.11920000000000000,0.19186000000000000,
0.13411000000000001,0.31228000000000000,0.14785000000000001,
0.38558999999999999,0.12872000000000000,0.13353000000000001,
0.13897999999999999,0.20521000000000000,0.13178000000000001,
0.14008999999999999,0.14468000000000000,0.13225000000000001,
0.79439000000000004,0.26307999999999998,0.17544999999999999,
0.33228000000000002,0.63861000000000001,0.18845999999999999,
0.36093999999999998,0.11133000000000000,0.11153000000000000,
0.88029000000000002,0.96462999999999999,0.96448999999999996,
0.11654000000000000,0.16206999999999999,0.22911000000000001,
0.61292000000000002,0.12328000000000000,0.17072999999999999,
0.14380999999999999,0.14602000000000001,0.32174999999999998,
0.13525999999999999,0.31498999999999999,0.23190000000000000,
0.23524999999999999,0.23554000000000000,0.32361000000000001,
0.20899999999999999,0.54813000000000001,0.14784000000000000,
0.09420000000000001,0.93078000000000005,0.20771999999999999,
0.19017000000000001,0.10370000000000000,0.19575999999999999,
0.11193000000000000,0.14513000000000001,0.28532000000000002,
0.33246999999999999,0.24446999999999999,0.27033000000000001,
0.11441999999999999,0.13206000000000001,0.29209000000000002,
0.18156000000000000,0.10234000000000000,0.65824000000000005,
0.13550000000000001,0.32285999999999998,0.56325000000000003,
0.11633000000000000,0.12889000000000000,0.78490000000000004,
0.15919000000000000,0.14621000000000001,0.10469000000000001,
0.09723999999999999,0.09600000000000000,0.91712000000000005
)
, tolerance = 1e-5)
})
test_that('comCrime produces correct results liang_g1', {
	set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results liang_g1')
    result <- sampler(100000, vy, mX, prior='liang_g1', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, 
		c(
0.9544200000000000,0.8700100000000000,0.3064800000000000,0.8621200000000000,
0.2789700000000000,0.6560600000000000,0.2510500000000000,0.4098600000000000,
0.2769200000000000,0.5556300000000000,0.4853300000000000,0.4531300000000000,
0.2581100000000000,0.2950200000000000,0.1721500000000000,0.1862400000000000,
0.2547200000000000,0.2384200000000000,0.3761000000000000,0.2205700000000000,
0.3786900000000000,0.3114700000000000,0.3950200000000000,0.2736600000000000,
0.2561700000000000,0.2076500000000000,0.2844200000000000,0.2215000000000000,
0.5234100000000000,0.2842700000000000,0.6075600000000000,0.2140700000000000,
0.2110600000000000,0.2602500000000000,0.3965100000000000,0.2248100000000000,
0.2425500000000000,0.2391600000000000,0.2235600000000000,0.8088000000000000,
0.3391400000000000,0.2436800000000000,0.3997600000000000,0.6137500000000000,
0.3200200000000000,0.5093200000000000,0.1987800000000000,0.2034700000000000,
0.8568300000000000,0.9657300000000000,0.9638600000000001,0.1940300000000000,
0.2670000000000000,0.3017900000000000,0.6335300000000000,0.2234100000000000,
0.3057200000000000,0.2673900000000000,0.2448100000000000,0.3417800000000000,
0.2296900000000000,0.4130500000000000,0.3107200000000000,0.3819300000000000,
0.4578400000000000,0.3973000000000000,0.4305400000000000,0.7434400000000000,
0.2540300000000000,0.1746400000000000,0.9404000000000000,0.2939500000000000,
0.4155700000000000,0.2014400000000000,0.2795300000000000,0.1957200000000000,
0.2625600000000000,0.4036600000000000,0.4234100000000000,0.3201700000000000,
0.3497100000000000,0.2157700000000000,0.2425300000000000,0.5873000000000000,
0.3849400000000000,0.1792100000000000,0.7591000000000000,0.2247600000000000,
0.3996000000000000,0.6204000000000000,0.1952700000000000,0.2182600000000000,
0.8663300000000000,0.2514200000000000,0.2246700000000000,0.1866900000000000,
0.1768500000000000,0.1768700000000000,0.9513600000000000
		)
, tolerance = 1e-5)
})
test_that('comCrime produces correct results liang_g2', {
	set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results liang_g2')
    result <- sampler(100000, vy, mX, prior='liang_g2', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, c(
		0.9544200000000000,0.8700100000000000,0.3064800000000000,0.8621200000000000,
		0.2789700000000000,0.6560600000000000,0.2510500000000000,0.4098600000000000,
		0.2769200000000000,0.5556300000000000,0.4853300000000000,0.4531300000000000,
		0.2581100000000000,0.2950200000000000,0.1721500000000000,0.1862400000000000,
		0.2547200000000000,0.2384200000000000,0.3761000000000000,0.2205700000000000,
		0.3786900000000000,0.3114700000000000,0.3950200000000000,0.2736600000000000,
		0.2561700000000000,0.2076500000000000,0.2844200000000000,0.2215000000000000,
		0.5234100000000000,0.2842700000000000,0.6075600000000000,0.2140700000000000,
		0.2110600000000000,0.2602500000000000,0.3965100000000000,0.2248100000000000,
		0.2425500000000000,0.2391600000000000,0.2235600000000000,0.8088000000000000,
		0.3391400000000000,0.2436800000000000,0.3997600000000000,0.6137500000000000,
		0.3200200000000000,0.5093200000000000,0.1987800000000000,0.2034700000000000,
		0.8568300000000000,0.9657300000000000,0.9638600000000001,0.1940300000000000,
		0.2670000000000000,0.3017900000000000,0.6335300000000000,0.2234100000000000,
		0.3057200000000000,0.2673900000000000,0.2448100000000000,0.3417800000000000,
		0.2296900000000000,0.4130500000000000,0.3107200000000000,0.3819300000000000,
		0.4578400000000000,0.3973000000000000,0.4305400000000000,0.7434400000000000,
		0.2540300000000000,0.1746400000000000,0.9404000000000000,0.2939500000000000,
		0.4155700000000000,0.2014400000000000,0.2795300000000000,0.1957200000000000,
		0.2625600000000000,0.4036600000000000,0.4234100000000000,0.3201700000000000,
		0.3497100000000000,0.2157700000000000,0.2425300000000000,0.5873000000000000,
		0.3849400000000000,0.1792100000000000,0.7591000000000000,0.2247600000000000,
		0.3996000000000000,0.6204000000000000,0.1952700000000000,0.2182600000000000,
		0.8663300000000000,0.2514200000000000,0.2246700000000000,0.1866900000000000,
		0.1768500000000000,0.1768700000000000,0.9513600000000000
	)
, tolerance = 1e-5)
})
test_that('comCrime produces correct results liang_g_n_approx', {
	set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results liang_g_n_approx')
    result <- sampler(100000, vy, mX, prior='liang_g_n_approx', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, 
c(
0.9538600000000000,0.8663999999999999,0.3010200000000000,0.8603200000000000,
0.2739900000000000,0.6520100000000000,0.2452700000000000,0.4059500000000000,
0.2718500000000000,0.5524900000000000,0.4741700000000000,0.4384200000000000,
0.2528300000000000,0.2880500000000000,0.1672800000000000,0.1802800000000000,
0.2535500000000000,0.2361300000000000,0.3673300000000000,0.2155200000000000,
0.3723700000000000,0.3060600000000000,0.3894600000000000,0.2676500000000000,
0.2503500000000000,0.2026900000000000,0.2797400000000000,0.2173300000000000,
0.5142900000000000,0.2770800000000000,0.5967800000000000,0.2101600000000000,
0.2054600000000000,0.2550200000000000,0.3879900000000000,0.2186000000000000,
0.2347400000000000,0.2367000000000000,0.2211600000000000,0.8075200000000000,
0.3348100000000000,0.2375300000000000,0.3937300000000000,0.6151000000000000,
0.3144100000000000,0.5036600000000000,0.1942100000000000,0.1982100000000000,
0.8570100000000000,0.9662600000000000,0.9642300000000000,0.1901300000000000,
0.2622900000000000,0.2975600000000000,0.6327100000000000,0.2167800000000000,
0.2998600000000000,0.2616300000000000,0.2390900000000000,0.3415800000000000,
0.2243800000000000,0.4054900000000000,0.3111500000000000,0.3709900000000000,
0.4499700000000000,0.3931500000000000,0.4244300000000000,0.7387100000000000,
0.2458700000000000,0.1697500000000000,0.9404400000000001,0.2874800000000000,
0.4062400000000000,0.1944800000000000,0.2763900000000000,0.1908900000000000,
0.2575600000000000,0.3969000000000000,0.4173400000000000,0.3142900000000000,
0.3471600000000000,0.2080200000000000,0.2342000000000000,0.5782800000000000,
0.3775600000000000,0.1750900000000000,0.7576300000000000,0.2211700000000000,
0.3931900000000000,0.6207300000000000,0.1911100000000000,0.2135000000000000,
0.8650099999999999,0.2473800000000000,0.2201700000000000,0.1823300000000000,
0.1718900000000000,0.1719200000000000,0.9506900000000000
)
, tolerance = 1e-5)
})
test_that('comCrime produces correct results liang_g_n_quad', {
	set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results liang_g_n_quad')
    result <- sampler(100000, vy, mX, prior='liang_g_n_quad', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, 
c(
0.9547500000000000,0.8645200000000000,0.2978900000000000,0.8612300000000001,
0.2703900000000000,0.6538100000000000,0.2420400000000000,0.4038500000000000,
0.2664800000000000,0.5470400000000000,0.4669400000000000,0.4362700000000000,
0.2494800000000000,0.2860500000000000,0.1656900000000000,0.1783700000000000,
0.2526200000000000,0.2333100000000000,0.3664700000000000,0.2129700000000000,
0.3644300000000000,0.3046700000000000,0.3824700000000000,0.2644800000000000,
0.2468800000000000,0.1990200000000000,0.2754100000000000,0.2146500000000000,
0.5100000000000000,0.2702800000000000,0.5911200000000000,0.2067600000000000,
0.2046500000000000,0.2507900000000000,0.3814400000000000,0.2163000000000000,
0.2318200000000000,0.2339300000000000,0.2166400000000000,0.8040000000000000,
0.3374100000000000,0.2373900000000000,0.3902400000000000,0.6205900000000000,
0.3077600000000000,0.5002600000000000,0.1910600000000000,0.1965700000000000,
0.8591100000000000,0.9672400000000000,0.9636900000000000,0.1886000000000000,
0.2591600000000000,0.2985600000000000,0.6283800000000000,0.2130700000000000,
0.2942200000000000,0.2571800000000000,0.2348800000000000,0.3375400000000000,
0.2208100000000000,0.4040000000000000,0.3101700000000000,0.3710000000000000,
0.4411800000000000,0.3922900000000000,0.4137700000000000,0.7348600000000000,
0.2431500000000000,0.1677400000000000,0.9396099999999999,0.2877300000000000,
0.3959600000000000,0.1909800000000000,0.2730300000000000,0.1890800000000000,
0.2532200000000000,0.3960300000000000,0.4130300000000000,0.3155900000000000,
0.3434800000000000,0.2052500000000000,0.2311600000000000,0.5709600000000000,
0.3740500000000000,0.1726400000000000,0.7559200000000000,0.2187300000000000,
0.3920100000000000,0.6177200000000000,0.1883800000000000,0.2105400000000000,
0.8637899999999999,0.2442100000000000,0.2182500000000000,0.1793900000000000,
0.1693700000000000,0.1690400000000000,0.9499600000000000
)
, tolerance = 1e-5)
})
test_that('comCrime produces correct results robust_bayarri1', {
    set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results robust_bayarri1')
    result <- sampler(100000, vy, mX, prior='robust_bayarri1', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, 
c(
0.9558700000000000,0.8629100000000000,0.2797800000000000,0.8637200000000000,
0.2550600000000000,0.6528100000000000,0.2287700000000000,0.3950700000000000,
0.2552300000000000,0.5435300000000000,0.4446000000000000,0.4110000000000000,
0.2342400000000000,0.2766700000000000,0.1507200000000000,0.1640300000000000,
0.2393100000000000,0.2202900000000000,0.3486100000000000,0.1979000000000000,
0.3426700000000000,0.2858000000000000,0.3641700000000000,0.2494500000000000,
0.2313000000000000,0.1853100000000000,0.2577300000000000,0.1995100000000000,
0.4929700000000000,0.2511600000000000,0.5707100000000001,0.1920000000000000,
0.1903100000000000,0.2306600000000000,0.3552500000000000,0.2001900000000000,
0.2162900000000000,0.2158000000000000,0.2012200000000000,0.8101400000000000,
0.3177900000000000,0.2259300000000000,0.3815600000000000,0.6185400000000000,
0.2895700000000000,0.4835000000000000,0.1760600000000000,0.1800300000000000,
0.8663100000000000,0.9680200000000000,0.9663500000000000,0.1726300000000000,
0.2432900000000000,0.2847100000000000,0.6304200000000000,0.1955800000000000,
0.2720200000000000,0.2349300000000000,0.2168200000000000,0.3333400000000000,
0.2034600000000000,0.3970400000000000,0.2986500000000000,0.3496700000000000,
0.4145400000000000,0.3834900000000000,0.3844200000000000,0.7272800000000000,
0.2260000000000000,0.1531200000000000,0.9433100000000000,0.2739600000000000,
0.3681500000000000,0.1761500000000000,0.2593500000000000,0.1710300000000000,
0.2370200000000000,0.3785900000000000,0.4004800000000000,0.3013000000000000,
0.3312800000000000,0.1895500000000000,0.2168000000000000,0.5435700000000000,
0.3488400000000000,0.1587200000000000,0.7543700000000000,0.2025700000000000,
0.3811400000000000,0.6143200000000000,0.1734900000000000,0.1976700000000000,
0.8639000000000000,0.2295000000000000,0.2074600000000000,0.1648000000000000,
0.1541600000000000,0.1549600000000000,0.9504100000000000
)
, tolerance = 1e-8)
})
test_that('comCrime produces correct results robust_bayarri2', {
	set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results robust_bayarri2')
    result <- sampler(100000, vy, mX, prior='robust_bayarri2', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, 
c(
0.9554700000000000,0.8661799999999999,0.2813900000000000,0.8647899999999999,
0.2527000000000000,0.6528700000000000,0.2293300000000000,0.3967100000000000,
0.2578200000000000,0.5439900000000000,0.4455400000000000,0.4116500000000000,
0.2351300000000000,0.2767100000000000,0.1504300000000000,0.1651200000000000,
0.2408900000000000,0.2209300000000000,0.3517600000000000,0.1973300000000000,
0.3427100000000000,0.2852600000000000,0.3645400000000000,0.2494100000000000,
0.2316100000000000,0.1845300000000000,0.2582100000000000,0.1981300000000000,
0.4883500000000000,0.2504300000000000,0.5685000000000000,0.1926200000000000,
0.1897200000000000,0.2326200000000000,0.3592300000000000,0.1994300000000000,
0.2151400000000000,0.2157300000000000,0.2020700000000000,0.8108300000000001,
0.3170800000000000,0.2236800000000000,0.3817900000000000,0.6190700000000000,
0.2907700000000000,0.4846300000000000,0.1767800000000000,0.1798500000000000,
0.8657800000000000,0.9684400000000000,0.9663100000000000,0.1731900000000000,
0.2431300000000000,0.2863100000000000,0.6275200000000000,0.1957300000000000,
0.2705200000000000,0.2367700000000000,0.2185800000000000,0.3319600000000000,
0.2047300000000000,0.3955600000000000,0.2993500000000000,0.3499500000000000,
0.4113700000000000,0.3822200000000000,0.3805300000000000,0.7270000000000000,
0.2276700000000000,0.1531400000000000,0.9429600000000000,0.2735100000000000,
0.3645800000000000,0.1750300000000000,0.2596000000000000,0.1713700000000000,
0.2358200000000000,0.3783900000000000,0.3987100000000000,0.3010400000000000,
0.3285000000000000,0.1902900000000000,0.2149000000000000,0.5373500000000000,
0.3462000000000000,0.1586900000000000,0.7538100000000000,0.2026600000000000,
0.3790000000000000,0.6165400000000000,0.1727600000000000,0.1965600000000000,
0.8648000000000000,0.2292200000000000,0.2062100000000000,0.1653000000000000,
0.1552200000000000,0.1549100000000000,0.9502100000000000
)
, tolerance = 1e-8)
})
test_that('comCrime produces correct results zellner_siow_gauss_laguerre', {
	set.seed(2019)
    comCrime <- get_comCrime()
    vy <- comCrime$vy
    mX <- comCrime$mX
    tic('comCrime produces correct results zellner_siow_gauss_laguerre')
    result <- sampler(100000, vy, mX, prior='zellner_siow_gauss_laguerre', modelprior='uniform', cores=cores)
    toc()
    expect_equal(result$vinclusion_prob, 
c(
0.9481000000000001,0.7679700000000000,0.2098300000000000,0.8056400000000000,
0.1881500000000000,0.6100900000000000,0.1574800000000000,0.3163600000000000,
0.1826100000000000,0.4641700000000000,0.2856300000000000,0.2411800000000000,
0.1680700000000000,0.2296200000000000,0.0928100000000000,0.1096300000000000,
0.1945200000000000,0.1645200000000000,0.2346800000000000,0.1307100000000000,
0.2140400000000000,0.1907300000000000,0.2358800000000000,0.1703700000000000,
0.1507400000000000,0.1191000000000000,0.1890200000000000,0.1330800000000000,
0.3101700000000000,0.1469800000000000,0.3874100000000000,0.1295700000000000,
0.1341700000000000,0.1388300000000000,0.2053900000000000,0.1308100000000000,
0.1396200000000000,0.1434500000000000,0.1339300000000000,0.7947400000000000,
0.2612800000000000,0.1715400000000000,0.3349800000000000,0.6340800000000000,
0.1889000000000000,0.3613300000000000,0.1111900000000000,0.1101900000000000,
0.8832000000000000,0.9655000000000000,0.9652300000000000,0.1153800000000000,
0.1618900000000000,0.2288500000000000,0.6148300000000000,0.1218700000000000,
0.1702600000000000,0.1428500000000000,0.1450600000000000,0.3202000000000000,
0.1330300000000000,0.3133700000000000,0.2295800000000000,0.2340500000000000,
0.2381500000000000,0.3239800000000000,0.2117200000000000,0.5454100000000000,
0.1486500000000000,0.0938500000000000,0.9327299999999999,0.2069100000000000,
0.1934400000000000,0.1034000000000000,0.1970700000000000,0.1114900000000000,
0.1440700000000000,0.2848100000000000,0.3390600000000000,0.2424000000000000,
0.2674700000000000,0.1134900000000000,0.1327000000000000,0.2865600000000000,
0.1802700000000000,0.1023900000000000,0.6498699999999999,0.1339500000000000,
0.3196600000000000,0.5682199999999999,0.1161100000000000,0.1274700000000000,
0.7790100000000000,0.1583900000000000,0.1447000000000000,0.1038900000000000,
0.0973700000000000,0.0960700000000000,0.9163800000000000
)
, tolerance = 1e-8)
})
